package com.stm.bi.repository;


import com.stm.bi.jdbc.DataSourceEnum;
import com.stm.bi.jdbc.DataSourceSwitch;
import com.stm.bi.repository.dataobject.AppOrganizationDO;
import com.stm.bi.repository.mapper.AppOrganizationMapper;
import com.stm.framework.repository.BaseRepository;
import com.stm.ucenter.dto.vo.org.OrganizationVO;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* 应用租户关联-仓储
*
* @author 阿俊
* @date 2024-01-22
*/
@Repository
public class AppOrganizationRepository extends BaseRepository<AppOrganizationMapper, AppOrganizationDO, AppOrganizationDO> {


    @DataSourceSwitch(DataSourceEnum.DATA_SYNC)
    public List<OrganizationVO> selectOrgList(){
        List<AppOrganizationDO> appOrganizationList = this.selectAll();
        Map<Long,OrganizationVO> organizations = new HashMap<>();
        for(AppOrganizationDO ao : appOrganizationList){
            OrganizationVO org  = new OrganizationVO();
            org.setId(ao.getOrgId());
            org.setNo(ao.getOrgNo());
            org.setName(ao.getOrgName());
            organizations.put(ao.getOrgId(),org);
        }
        return organizations.values().stream().collect(Collectors.toList());
    }
}
